package com.cloud.rocketmqtxprovider.component;

import com.cloud.rocketmqtxprovider.config.RocketProviderConfig;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.TransactionSendResult;
import org.apache.rocketmq.common.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@SuppressWarnings("all")
public class SendMessage {

    @Autowired
    private RocketProviderConfig config;

    public TransactionSendResult sendMessage(String data, String topic)throws MQClientException {
        Message message = new Message(topic,data.getBytes());
        return config.getTransactionMQProducer().sendMessageInTransaction(message, null);
    }
}
